/**
 * 
 */
package br.com.ufrn.aipetro.ga.controller.device;

import java.util.List;

import br.com.ufrn.aipetro.ga.controller.interfaces.AbstractController;
import br.com.ufrn.aipetro.ga.domain.entity.mesh.Mesh;
import br.com.ufrn.aipetro.ga.domain.entity.plant.Plant;
import br.com.ufrn.aipetro.ga.domain.entity.unit.Unit;
import br.com.ufrn.aipetro.ga.persist.interfaces.DaoFactory;

/**
 * @author Andre
 *
 */
public class MeshController extends AbstractController<Mesh> {
	
	DaoFactory daoFactory;
	
	public MeshController(DaoFactory factory) {
		this.daoFactory = factory;
		setModel(new Mesh());
	}
	
	public void changePlant(Plant plant) {
		getModel().setPlant(plant);
	}
	
	public void changeName(String name) {
		getModel().setName(name);
	}
	
	public void persistDelete(Mesh mesh) {
		daoFactory.beginTransaction();
		daoFactory.createMeshDao().delete(mesh);
		daoFactory.commitTransaction();
	}
	
	public void persistInsert() {
		daoFactory.beginTransaction();
		daoFactory.createMeshDao().insert(getModel());
		daoFactory.commitTransaction();
	}
	
	public void persistUpdate() {
		daoFactory.beginTransaction();
		daoFactory.createMeshDao().update(getModel());
		daoFactory.commitTransaction();
	}
	
	public List<Mesh> persistSearchAll() {
		daoFactory.beginTransaction();
		List<Mesh> listUnit = daoFactory.createMeshDao().searchAll();
		daoFactory.commitTransaction();
		return listUnit;
	}
	
	public List<Unit> persistSearchAllUnit() {
		daoFactory.beginTransaction();
		List<Unit> listUnit = daoFactory.createUnitDao().searchAll();
		daoFactory.commitTransaction();
		return listUnit;
	}
	
	public List<Plant> persistSearchPlantByUnit(Unit unit) {
		daoFactory.beginTransaction();
		List<Plant> listPlant = daoFactory.createPlantDao().searchByUnit(unit);
		daoFactory.commitTransaction();
		return listPlant;
	}
	
	public List<Mesh> persistSearchByExample(Mesh example) {
		daoFactory.beginTransaction();
		List<Mesh> meshList = daoFactory.createMeshDao().searchByExample(example);
		daoFactory.commitTransaction();
		return meshList;
	}

}
